<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>页面标题</title>
  </head>
  <body></body>
  <script>
    //目标
    // 1.可复用的最小子问题：start +sum(start +1,end);
    // 2.终止条件：start === end
    /*
     *分析
     *1+2+3
     *sum(1,3)
     *1+2+3
     *1+(2,3)
     *=> 1+sum(2,3)
     *
     *sum(2,3)
     *2+3
     *=> 2+sum(3,3)
     *
     * sum(3,3)
     * 3
     * => 3
     */

    function sum(start, end) {
      if (start === end) {
        return start;
      }
      if (start < end) {
        return start + sum(start + 1, end);
      } else {
        return 0;
      }
    }
    console.log(sum(1, 3));
  </script>
</html>
<style scoped></style>
